
package gal.game.manager
{
	import com.zero.framework.interfaces.INotification;
	import com.zero.framework.interfaces.INotifyResponder;
	import com.zero.framework.observer.Facade;
	
	import gal.game.core.AppFacade;
	import gal.game.core.layers.BackgroundLayer;
	import gal.game.core.layers.RoleLayer;
	import gal.game.notification.galScene.GalSceneNotification;
	
	import mx.core.Singleton;
	
	/**
	 * @author 缺硒
	 */
	public class SceneManger implements INotifyResponder
	{
		private static var __instance:SceneManger;
		
		private var _background:BackgroundLayer;
		private var _roleLayer:RoleLayer;
		
		public static function getInstance():SceneManger
		{
			if(__instance == null)
				__instance = new SceneManger(new Singleton());
			return __instance;
		}
		
		// 构造函数
		public function SceneManger(s:Singleton)
		{
			AppFacade.getInstance().registerResponder(this);
		}
		
		/**
		 * 绑定背景
		 * @param target 
		 */		
		public function bindBackground(target:BackgroundLayer):void
		{
			_background = target;
		}
		
		/**
		 * 绑定角色层
		 * @param target 
		 */		
		public function bindRoleLayer(target:RoleLayer):void
		{
			_roleLayer = target;
		}
		
		public function get notificationList():Array
		{
			return [
				GalSceneNotification.SWITCH_BGD,
				GalSceneNotification.SHOW_ROLE
			];
		}
		
		public function notifyHandler(notification:INotification):void
		{	
			var data:Object = notification.getBody();
			switch(notification.getName())
			{
				case GalSceneNotification.SWITCH_BGD:
					onSwitchBackground(data.bid);
					break;
				case GalSceneNotification.SHOW_ROLE:
					onShowRole(data.rid, data.x);
					break;
				default :
					throw new Error(Facade.ERROR_NOTIFICATION_NOT_SEEN);
					break;
			}
		}
		
		/**
		 * 转换背景
		 * @param bid 背景id 
		 */		
		private function onSwitchBackground(bid:String):void
		{
			_background.switchBackground(bid);
		}
		
		/**
		 * 显示角色
		 * @param rid 
		 * @param x
		 */		
		private function onShowRole(rid:String, px:Number):void
		{
			_roleLayer.showRole(rid, px);
		}
		
	}
}
class Singleton{}